package com.richpay.basejava.base16;

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * 外国的月份 0-11，咱们的月份1-12
 */
public class CalendarDemo {
    public static void main(String[] args) {
        //1.通过调用静态方法返回本类类型的对象
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);//目前还是7月
        int day = calendar.get(Calendar.DATE);
        int hour = calendar.get(Calendar.HOUR);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
        System.out.println(year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second);


        Date date = calendar.getTime();
        System.out.println("date=" + date);

        TimeZone timeZone = calendar.getTimeZone();
        System.out.println("timeZone=" + timeZone.getDisplayName());

        //在当前时间的基础上加上2年后的时间

        calendar.add(Calendar.YEAR, 2);
        calendar.add(Calendar.MONTH, 1);
        year = calendar.get(Calendar.YEAR);
        month = calendar.get(Calendar.MONTH);
        System.out.println(year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second);

    }
}
